# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=store
pkgname=haskell-store
pkgver=0.7.16
pkgrel=46
pkgdesc="Fast binary serialization"
url="https://github.com/mgsloan/store"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-async' 'haskell-base-orphans' 'haskell-base64-bytestring'
         'haskell-bifunctors' 'haskell-contravariant' 'haskell-cryptohash' 'haskell-free'
         'haskell-hashable' 'haskell-hspec' 'haskell-hspec-smallcheck' 'haskell-lifted-base'
         'haskell-monad-control' 'haskell-mono-traversable' 'haskell-network' 'haskell-primitive'
         'haskell-resourcet' 'haskell-safe' 'haskell-smallcheck' 'haskell-store-core'
         'haskell-syb' 'haskell-th-lift' 'haskell-th-lift-instances' 'haskell-th-orphans'
         'haskell-th-reify-many' 'haskell-th-utilities' 'haskell-unordered-containers'
         'haskell-vector' 'haskell-void')
makedepends=('ghc' 'uusi' 'haskell-clock' 'haskell-hspec-discover')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('0b8c79cf9c0cc489535a9ca9a17cd2e4e16c3828d9327b2127558abcabed363c30b834f88d002053d3a8ddac0ba08cac53e78c95ef683e04973fa4842d150d54')

prepare() {
    cd $_hkgname-$pkgver
    uusi -d nats $_hkgname.cabal
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
            -f-comparison-bench -f-small-bench
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
